Structured Outputs
2024/8/6に発表された
指定したJSON schemaに基づいて返答を返す
response_formatにJSON Schemaを指定するだけ
code:例
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-2024-08-06",
"messages": [
{
"role": "system",
"content": "You are a helpful math tutor. Guide the user through the solution step by step."
},
{
"role": "user",
"content": "how can I solve 8x + 7 = -23"
}
],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "math_reasoning",
"schema": {
"type": "object",
"properties": {
"steps": {
"type": "array",
"items": {
"type": "object",
"properties": {
"explanation": { "type": "string" },
"output": { "type": "string" }
},
"additionalProperties": false
}
},
"final_answer": { "type": "string" }
},
"additionalProperties": false
},
"strict": true
}
}
}'